package com.sky.mapper.user;


import cn.hutool.core.date.DateTime;
import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.pojo.Orders;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
@Mapper
public interface OrderMapper {
    /**
     * 插入订单数据
     * @param order
     */
    void insert(Orders order);

    /**
     * 根据用户id查询预计送达时间
     * @param id
     * @return
     */
    @Select("select estimated_delivery_time from orders where user_id = #{id} and order_time = #{orderTime}")
    LocalDateTime getEstimatedDeliveryTime(Long id,LocalDateTime orderTime);

    /**
     * 根据状态和下单时间查询订单
     * @param status
     * @param orderTime
     */
    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> selectByStatusAndTime(Integer status, Date orderTime);

    /**
     * 更新订单状态
     * @param cancelledOrder
     * @param id
     */
    @Update("update orders set status = #{status} where id = #{id}")
    void updateOrderStatusById(Integer cancelledOrder, Long id);

    /**
     * 根据订单号查询订单状态
     * @param number
     * @return
     */
    @Select("select status from orders where number = #{number}")
    Integer selectOrderStatusByOrderNumber(String number);

    /**
     * 根据用户id查询订单
     * @param userId
     * @return
     */
    @Select("select * from orders where user_id = #{userId}")
    List<Orders> selectByUserId(Long userId);

    /**
     * 分页条件查询并按下单时间排序
     * @param ordersPageQueryDTO
     */
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);
}